From e600a0723780dcd8ddb3452a50405968241e007f Mon Sep 17 00:00:00 2001 From: Emmanuele Bassi Date: Thu, 19 Nov 2020 14:46:01 +0000 Subject: [PATCH] a11y: Skip atspi.Cache signals for hidden elements If the accessible object is hidden, we can skip the emission of the AddAccessible and RemoveAccessible signals on the cache, as those objects won't be visible in the accessibility tree. --- gtk/a11y/gtkatspicache.c | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/gtk/a11y/gtkatspicache.c b/gtk/a11y/gtkatspicache.c index 81bfd030f2..10736341e5 100644 --- a/gtk/a11y/gtkatspicache.c +++ b/gtk/a11y/gtkatspicache.c @@ -176,6 +176,18 @@ static void emit_add_accessible (GtkAtSpiCache *self, GtkAtSpiContext *context) { + GtkATContext *at_context = GTK_AT_CONTEXT (context); + + /* If the context is hidden, we don't need to update the cache */ + if (gtk_at_context_has_accessible_state (at_context, GTK_ACCESSIBLE_STATE_HIDDEN)) + { + GtkAccessibleValue *is_hidden = + gtk_at_context_get_accessible_state (at_context, GTK_ACCESSIBLE_STATE_HIDDEN); + + if (gtk_boolean_accessible_value_get (is_hidden)) + return; + } + GVariantBuilder builder = G_VARIANT_BUILDER_INIT (G_VARIANT_TYPE ("(" ITEM_SIGNATURE ")")); collect_object (self, &builder, context); @@ -194,6 +206,18 @@ static void emit_remove_accessible (GtkAtSpiCache *self, GtkAtSpiContext *context) { + GtkATContext *at_context = GTK_AT_CONTEXT (context); + + /* If the context is hidden, we don't need to update the cache */ + if (gtk_at_context_has_accessible_state (at_context, GTK_ACCESSIBLE_STATE_HIDDEN)) + { + GtkAccessibleValue *is_hidden = + gtk_at_context_get_accessible_state (at_context, GTK_ACCESSIBLE_STATE_HIDDEN); + + if (gtk_boolean_accessible_value_get (is_hidden)) + return; + } + GVariant *ref = gtk_at_spi_context_to_ref (context); g_dbus_connection_emit_signal (self->connection, -- 2.30.2